clear

*This do file runs descriptives
*Last updated: May 12, 2022

*Insert your root folder location below
cd  "FOLDER LOCATION HERE

use "EVRR_Dataset.dta"

********************Generate Enfranchisement Years*****************************


*Creating DVAdoptYr and DVImpYear 
sort stateid year
by stateid: gen DVAdoptYr = 0
by stateid: replace DVAdoptYr = 1 if evrr_dejure==1 & evrr_dejure[_n-1]==0
by stateid: replace DVAdoptYr = 1 if evrr_dejure==1 & evrr_dejure[_n-1]==.e
by stateid: replace DVAdoptYr = 1 if evrr_dejure==1 & evrr_dejure[_n-1]==.a
list stateid country year if DVAdoptYr==1

*Check to identify reversals
list stateid country year if evrr_dejure==0 & evrr_dejure[_n-1]==1 & stateid==stateid[_n-1]

*Reversals include: Angola, Armenia, Cambodia, Fiji, Guyana
*Morocco, Marshall Islands, Panama, South Africa, San Marino, Turkmenistan

*Of these, Angola, Armenia, Cambodia, Guyana, San Marino reversed once
*For these, no additional tweaks are required

*For Fiji, Morocco, Marshall Islands, Panama, South Africa, and Turkmenistan
*Main variable uses first adoption

replace DVAdoptYr = 0 if stateid=="MOR" & year==2011
replace DVAdoptYr = 0 if stateid=="SAF" & year==2009
replace DVAdoptYr = 0 if stateid=="TKM" & year==1992
replace DVAdoptYr = 0 if stateid=="FJI" & year==2013
replace DVAdoptYr = 0 if stateid=="MSI" & year==2019
replace DVAdoptYr = 0 if stateid=="PAN" & year==2006


*First Year Implement*
sort stateid year
by stateid: gen DVImpYr = 0
by stateid: replace DVImpYr = 1 if evrr_defacto==1 & evrr_defacto[_n-1]==0
by stateid: replace DVImpYr = 1 if evrr_defacto==1 & evrr_defacto[_n-1]==.e
by stateid: replace DVImpYr = 1 if evrr_defacto==1 & evrr_defacto[_n-1]==.a
list stateid country year if DVImpYr==1

*Check to identify reversals
list stateid country year if evrr_defacto==0 & evrr_defacto[_n-1]==1 & stateid==stateid[_n-1]
*Reversals include: Afghanistan, Armenia, Benin, Burundi [2x], Cambodia, 
*Equatorial Guinea, Guinea-Bissau, Guyana, Morocco, Marshall Islands, Niger
*South Africa, San Marino

*For those with two DVImp=1 years, we'll code from the first

replace DVImpYr = 0 if stateid=="BEN" & year==2011
replace DVImpYr = 0 if stateid=="BUI" & year==2010
*replace DVImpYr = 0 if stateid=="CHA" & year==2011
replace DVImpYr = 0 if stateid=="EQG" & year==2019
replace DVImpYr = 0 if stateid=="GNB" & year==2013
replace DVImpYr = 0 if stateid=="MOR" & year==2011
replace DVImpYr = 0 if stateid=="SAF" & year==2009
replace DVImpYr = 0 if stateid=="STP" & year==2016

sort stateid year


**********************Merge NELDA (elections)***************
*Cutnote: remove folder root in final version
merge m:m stateid year using "ExtraDatasets/nelda.dta"
*_m==1 are all the years that didn't have elections
list country year if _m==2 & year>1949
*A collection of former states and autonomous regions
drop if _m==2
gen elecyear=0
replace elecyear=1 if _m==3
drop _m

sort stateid year

*NELDA has more than 1 observation in a year, so we end up with double entries
list country year if year==year[_n-1]
*Since the key variable - elecyear - is 1 for all the double entries, delete 1
drop if year==year[_n-1]

sort stateid year

save "EVRR_Descriptives.dta", replace

****************Prepping T&U data for merge*********************

clear

use "ExtraDatasets/diaspora_enfranchisement_data.dta", replace

do "z_stateid_crosswalk.do"

list country year if stateid=="xxx"
*** It's small countries not included in EVRR
*** Except for Cote D'Ivore, which seems to be a chachrter mix-up in transfer
*** Let's fix it

replace stateid ="CDI" if cono==51 


*Tag the TU variables for merge with main dataset

rename country TU_country
rename newextvote TU_newextvote
rename idea2013 TU_idea2013
rename pop TU_pop
rename gdpdoll TU_gdpdoll
rename rgdpch TU_rgdpch
rename econcat TU_econcat
rename gdprate TU_gdprate
rename remit TU_remit
rename lngdp TU_lngdp
rename lnpop TU_lnpop
rename electyear TU_electyear
rename referendum TU_referendum
rename execrlc TU_execrlc
rename rlc TU_rlc
rename gov1rlc TU_gov1rlc
rename kaufcorr TU_kaufcorr
rename ti_cpi TU_ti_cpi
rename ceeurope TU_ceeurope
rename lndur TU_lndur
rename transit TU_transit
rename politydur TU_politydur
rename cap6lag TU_cap6lag
rename queenlag TU_queenlag
rename k6partnr TU_k6partnr
rename exp6delco TU_exp6delco
rename k6lag TU_k6lag
rename remitrate TU_remitrate
rename cono TU_cono
rename debtrate TU_debtrate
rename debtdoll TU_debtdoll
rename lnwbdebt TU_lnwbdebt
rename k06delta TU_k06delta
rename qdelta TU_qdelta
rename cap6delta TU_cap6delta
rename par6delta TU_par6delta
rename exp6delta TU_exp6delta
rename k6delta TU_k6delta
rename curracct TU_curracct
rename currdec TU_currdec
rename govdebtrr TU_govdebtrr
rename extdebtrr TU_extdebtrr
rename lngovdrr TU_lngovdrr
rename lnextdrr TU_lnextdrr
rename govdebtimf TU_govdebtimf
rename govdebtwb TU_govdebtwb
rename govdebtoecd TU_govdebtoecd
rename extdebt TU_extdebt
rename lngovdimf TU_lngovdimf
rename lngovdwb TU_lngovdwb
rename lngovdoecd TU_lngovdoecd
rename govdebt TU_govdebt
rename politydem TU_politydem
rename newdem TU_newdem
rename newdem2 TU_newdem2
rename legengl TU_legengl
rename legsoc TU_legsoc
rename legfren TU_legfren
rename leggerm TU_leggerm
rename legscan TU_legscan
rename colbrit TU_colbrit
rename colfren TU_colfren
rename colspan TU_colspan
rename trenchfilt TU_trenchfilt

label variable TU_electyear  "Election year"
label variable TU_referendum  "Referendum year"
label variable TU_colb  "British empire"
label variable TU_colf  "French empire"
label variable TU_cols  "Spanish empire"
label variable TU_legengl  "English legal heritage"
label variable TU_lndur  "ln(years since regime change)"
label variable TU_lngdp  "ln(per-capita GDP)"
label variable TU_lnpop  "ln(population)"
label variable TU_ceeurope  "Central or Eastern Europe"

*And drop the variables generated by the hazard model
drop _st
drop _d
drop _t
drop _t0

sort stateid year

merge stateid year using "EVRR_Descriptives.dta"

drop _merge

***Appendix 3.2 - Table 1***

tab cap_delta_TUidea TU_cap6delta, row

***Appendix 3.2 - Table 2***

tab cent_delta_TUidea TU_k6delta, row


*****************Generate results for Table 1*****************

******Blais et al 2001

merge m:m stateid using "ExtraDatasets/blais.dta"

tab blais_enfranchised if year==2000

*Note: this is the coding from Blais's universe of cases, which includes democracies
*There are 2 types of missing values: "NA" are democracies, empty are 
*non-democracies. 


*Compare Blais to EVRR legal enfranchisement
tab evrr_dejure blais_enfranchised if year==2000 & blais_enfranchised!=99, cell
list country evrr_dejure blais_enfranchised if evrr_dejure!=blais_enfranchised & year==2000 & blais_enfranchised!=.


*Compare Blais to EVRR implementation
tab evrr_defacto blais_enfranchised if year==2000  & blais_enfranchised!=99, cell
list country evrr_defacto blais_enfranchised if evrr_defacto!=blais_enfranchised & year==2000 & blais_enfranchised!=.


drop _merge

*****Sussex
sort stateid year

merge m:m stateid using "ExtraDatasets/collyer.dta"


*Give  date of 2007 for all the cases collyer has that are unmatched in EVRR
*The year reflects the time collyer & Vathi made their dataset
replace year = 2007 if _merge==2

tab collyer if year==2007

*Generate a variable that captures voting abroad in all collyer codes
*We need to combine to coding categories for Collyer - voting abroad in
*home districts, and voting abroad for abroad districts

gen collyer_abroad = 0
replace collyer_abroad=1 if collyer==2
replace collyer_abroad=1 if collyer==3
replace collyer_abroad=99 if collyer==0

tab collyer collyer_abroad if year==2007

*Compare collyer_abroad to EVRR legal enfranchisement
tab evrr_dejure collyer_abroad if year==2007 & collyer_abroad!=99, cell
list country evrr_dejure collyer if evrr_dejure!=collyer_abroad & year==2007 & evrr_dejure!=.  & collyer_abroad!=99
*Some close calls, but a few differences

*Compare collyer_abroad to EVRR implementation
tab evrr_defacto collyer_abroad if year==2007  & collyer_abroad!=99, cell
list country evrr_defacto collyer if evrr_defacto!=collyer_abroad & year==2007 & evrr_defacto!=.  & collyer_abroad!=99


drop _merge

******Compare ELECLAW*******

sort stateid year

merge m:m stateid year using "ExtraDatasets/eleclaw.dta"

*Should be no unmerged observatios

*gen dummies for eligiblity using key variables
*We use voting rights eligibility for non-residents
*The cut-off is posted below
*past residence within specific period - 0.5
*limited categories only (such as military personnel, embassy staff, 
*employees of public companies) OR eligible but no implementing legislation 0.25
*P.24

gen eligible_leg = 0
replace eligible_leg = 1 if VNRELINALE == 0.5
replace eligible_leg = 1 if VNRELINALE == 0.67
replace eligible_leg = 1 if VNRELINALE == 0.75
replace eligible_leg = 1 if VNRELINALE == 1
replace eligible_leg = . if VNRELINALE == .

*Little variance for exec elections
gen eligible_exec = 0
replace eligible_exec = 1 if VNRELINAPR ==1
replace eligible_exec = . if VNRELINAPR ==.


*Generate a dummy for any eligibility

gen eleclaw_eligible = .
replace eleclaw_eligible = 0 if eligible_leg==0
replace eleclaw_eligible = 0 if eligible_exec==0
replace eleclaw_eligible = 1 if eligible_leg==1
replace eleclaw_eligible = 1 if eligible_exec==1



*We'll examine using 2015, the year with the most observations

tab eleclaw_eligible if year==2015


*Compare eleclaw to EVRR legal enfranchisement
tab evrr_dejure eleclaw_eligible if year==2015, cell
list country if eleclaw_eligible==0 & evrr_dejure==1 & year==2015



*Compare eleclaw to EVRR implementation
tab evrr_defacto eleclaw_eligible if year==2015, cell
list country if eleclaw_eligible==0 & evrr_defacto==1 & year==2015

*Now compare with missing values
tab evrr_dejure eleclaw_eligible if year==2015, cell missing
tab evrr_defacto eleclaw_eligible if year==2015, cell missing

drop _merge

*****EMIX

sort stateid year

merge m:m stateid using "ExtraDatasets/emix.dta"

*Should be no unmerged observatios

*gen dummies for enfranchisement using active suffrage rights
*We will use rights in either [or both] presidential and lower house elections
*EMIX coding has a value of "1" that corresponds with EVRR criteria
*View section 3.1  of codebook for explanation

*First, lower house
gen leg_rights_emix = .
replace leg_rights_emix = 1 if suffact_2_2 == 1
replace leg_rights_emix = 0 if suffact_2_2 == 0

*Now, executive
gen exec_rights_emix = .
replace exec_rights_emix = 1 if suffact_1 ==1
replace exec_rights_emix = 0 if suffact_1 ==0


*Generate a dummy for any eligibility

gen emix = .
replace emix = 0 if leg_rights_emix==0
replace emix = 0 if exec_rights_emix==0
replace emix = 1 if leg_rights_emix==1
replace emix = 1 if exec_rights_emix==1


*We'll examine using 2017, the year of publication

tab emix if year==2017


*Compare emix to EVRR legal enfranchisement
tab evrr_dejure emix if year==2017, cell
list country if emix==0 & evrr_dejure==1 & year==2017



*Compare emix to EVRR implementation
tab evrr_defacto emix if year==2017, cell
list country if emix==0 & evrr_defacto==1 & year==2017


*Finally, compare with missing values
tab evrr_dejure emix if year==2017, cell missing
tab evrr_defacto emix if year==2017, cell missing

drop _merge


*****Comparing IDEA

sort stateid year

gen temp_id = 1 + [_n-1]

gen temp_dejure = 0
replace temp_dejure = 1 if DVAdoptYr==1
replace temp_dejure = 1 if temp_dejure[_n-1] ==1 & stateid==stateid[_n-1]

gen dejure_holder = 1 if temp_dejure==1 & temp_dejure[_n-1]!=1 & country==country[_n-1]
replace dejure_holder = 1 if temp_dejure==1 & year==1950
replace dejure_holder = 9999 if temp_dejure==0 & year==2020
gen adoption_year = dejure_holder if dejure_holder==9999
replace adoption_year = dejure_holder if dejure_holder==1 & year==1950
replace adoption_year = year if dejure_holder==1 & year!=1950

replace adoption_year = adoption_year[_n-1] if adoption_year==. & country==country[_n-1]
gsort stateid -year
replace adoption_year = adoption_year[_n-1] if adoption_year==. & country==country[_n-1]
sort temp_id

drop temp_id

sort stateid year

gen temp_id = 1 + [_n-1]

gen temp_defacto = 0
replace temp_defacto = 1 if DVImpYr==1
replace temp_defacto = 1 if temp_defacto[_n-1] ==1 & stateid==stateid[_n-1]

gen defacto_holder = 1 if temp_defacto==1 & temp_defacto[_n-1]!=1 & country==country[_n-1]
replace defacto_holder = 1 if temp_defacto==1 & year==1950
replace defacto_holder = 9999 if temp_defacto==0 & year==2020
gen implementation_year = defacto_holder if defacto_holder==9999
replace implementation_year = defacto_holder if defacto_holder==1 & year==1950
replace implementation_year = year if defacto_holder==1 & year!=1950

replace implementation_year = implementation_year[_n-1] if implementation_year==. & country==country[_n-1]
gsort stateid -year
replace implementation_year = implementation_year[_n-1] if implementation_year==. & country==country[_n-1]
sort temp_id

drop temp_id

*First, count all countries
count if year==2010 & TU_idea2013!=. & adoption_year!=.
list country TU_idea2013 adoption_year implementation_year if year==2010
*195 cases

*Compare measures
count if year==2010 & TU_idea2013==adoption_year

count if year==2010 & TU_idea2013==implementation_year


***Implementation Gap across regions***

sort country year
gen year_adopt = year if DVAdoptYr==1
by country: replace year_adopt = year_adopt[_n-1] if year_adopt==.
by country: replace year_adopt = year_adopt[_n+1] if year_adopt==.
gen year_implement = year if DVImpYr==1
by country: replace year_implement = year_implement[_n-1] if year_implement==.
by country: replace year_implement = year_implement[_n+1] if year_implement==.
gen implement_gap = year_implement - year_adopt

*Let's take a look

list country year_adopt year_implement implement_gap if year==2020

*There are some odd ones. Let's look to see where the problem is a lack of info (".e" prior to implementaiton)

gen before_imp = 1 if DVImpYr[_n+1]==1

list country year if evrr_defacto==.e & before_imp==1

*interestingly, not many countries. It's not just unknown values driving results


***Check out the averages***
sum implement_gap if year==2020

sum implement_gap if year==2020 & un_continent_name=="Africa"
sum implement_gap if year==2020 & un_continent_name=="Americas"
sum implement_gap if year==2020 & un_continent_name=="Asia"
sum implement_gap if year==2020 & un_continent_name=="Europe"
sum implement_gap if year==2020 & un_continent_name=="Oceania"


***Look closely at the non-implementers***

list country year_adopt if year==2020 & year_implement==. & year_adopt!=.

*There are 18 countries in this list!

sum year_adopt if year==2020 & year_implement==. & year_adopt!=.


*****************Generate the descriptive figures*************

gen evrr_modiplodummy = evrr_modiplo
gen evrr_mopostdummy = evrr_mopost
gen evrr_moproxydummy = evrr_moproxy
gen evrr_moonlinedummy = evrr_moonline
replace evrr_modiplodummy = 1 if evrr_modiplo==2
replace evrr_mopostdummy = 1 if evrr_mopost==2
replace evrr_moproxydummy = 1 if evrr_moproxy==2
replace evrr_moonlinedummy = 1 if evrr_moonline==2
collapse (sum) evrr* elecyear, by(year)
twoway line evrr_dejure year if year<2021, lc(gs0)||line evrr_defacto year if year<2021, lc(gs5) legend(lab(1 "Adopted") lab(2 "Implemented")) scheme(s1mono) title("Rise of Extraterritorial Voting Rights") xtitle("")
twoway line evrr_inexec year if year>1979 & year<2021, lc(gs5)||line evrr_inleg year if year>1979 & year<2021, lc(gs0)||line evrr_inleg_reps year if year>1979 & year<2021, lc(gs0) lp(dash) legend(lab(1 "Executive") lab(2 "Legislative") lab(3 "Diaspora Seats")) scheme(s1mono) title("External Voting By Election Type") xtitle("")
graph export "Fig4c.png", replace width(1280)
twoway line evrr_modiplodummy year if year>1979 & year<2021, lc(gs0)||line evrr_mopostdummy year if year>1979 & year<2021, lc(gs3)||line evrr_moproxydummy year if year>1979 & year<2021, lc(gs5)||line evrr_moonlinedummy year if year>1979 & year<2021, lc(gs7) lp(dash) legend(lab(1 "Diplomatic Stations") lab(2 "Postal Voting") lab(3 "Proxy Voting") lab(4 "Online Voting")) scheme(s1mono) title("External Voting By Voting Method") xtitle("")
graph export "Fig4b.png", replace width(1280)

clear
use "EVRR_Descriptives.dta", replace

collapse (mean) evrr* elecyear, by(year)
twoway line evrr_elregres year if year>1979 & year<2021, lc(gs0) scheme(s1mono) title("Rise of Registration Requirements") xtitle("") ytitle("") ylab(0.2 "20%" 0.3 "30%" 0.4 "40%" 0.5 "50%" 0.6 "60%" 0.7 "70%") legend(on label(1 "% of Countries Requiring Prior Registration"))
graph export "Fig4a.png", replace width(1280)

clear
use "EVRR_Descriptives.dta", replace

gen DVAdptYr = 0
replace DVAdptYr = 1 if evrr_dejure==1 & evrr_dejure[_n-1]==0
gen DVImp = 0
replace DVImp = 1 if evrr_defacto==1 & elecyear==1
collapse (sum) DVAdptYr DVImp elecyear, by(year)
label variable elecyear "National Elections"
label variable DVImp "Elections with External Voting"
gen shareXTV = 100*DVImp/elecyear
label variable shareXTV "% w/ External Voting"
twoway line elecyear year if year<2021, lc(gs0) || line shareXTV year if year<2021, lc(gs0) lp(dash) || bar DVImp year, title("National Elections with External Voting") scheme(s1mono) bcolor(gs2) xtitle("")
graph export "FIG3b.png", replace width(1280)

clear
use "EVRR_Descriptives.dta", replace

collapse (sum) DVAdoptYr elecyear, by(year)
twoway bar DVAdoptYr year, title("Count of Legal Extension of External Voting Rights by Year") xtitle("year") xlab(1950 "1950" 1955 "1955" 1960 "1960" 1965 "1965" 1970 "1970" 1975 "1975" 1980 "1980" 1985 "1985" 1990 "1990" 1995 "1995" 2000 "2000" 2005 "2005" 2010 "2010" 2015 "2015" 2020 "2020") ytitle("") ylab(0 "0" 5 "5" 10 "10")
graph export "FIG3a.png", replace width(1280)
